
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="https://demo.easyweb.vip/iframe/assets/module/admin.css?v=318"/>
    <script type="text/javascript" src="/static/js/jquery-1.7.2.js"></script>
    <style>
        body .tox-tinymce-aux { z-index: 19892000; }
        .dc{ color: red; }
    </style>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
	        <div class="layui-form">
				<div class="layui-form toolbar">
					<div class="layui-form-item">
						<div class="layui-inline">
							<div class="layui-inline">
									<label class="layui-form-label"><span style="font-size: 16px;">请选择目录</span></label>
							</div>
							
							<div class="layui-inline">
								<div class="layui-input-inline mr0">
									<select name="firstMenu" lay-filter="firstMenu"  lay-search  id="firstMenu">
										<option value="">选择一级目录</option>
										<span th:each="menu:${firstMenu}">
											<option th:value="${menu.cno}">[[${menu.cname}]]</option>
										</span>
									</select>
								</div><span class="dc"> * </span>
							</div>
							<div class="layui-inline">
								<div class="layui-input-inline mr0">
									<select name="secondMenu" lay-filter="secondMenu"  lay-search  id="secondMenu">
										<option value="">选择二级目录</option>
									</select>
								</div><span class="dc"> * </span>
							</div>
							<div class="layui-inline">
								<div class="layui-input-inline mr0">
									<select name="endMenu" lay-filter="endMenu"  lay-search  id="endMenu">
										<option value="">选择目录</option>
									</select>
								</div><span class="dc"> * </span>
							</div>
						</div>
					</div>
				</div>
			</div>
            <textarea id="demoEditor"></textarea>
        </div>
        <div class="layui-form-item">
           <div class="layui-input-block text-center">
               <button ew-event="closeThisTabs" type="button" class="layui-btn layui-btn-primary" id="cloneDemoEdtInsertContent">&emsp;清除&emsp;</button>
               <button class="layui-btn" lay-filter="eQuestionSubmit" lay-submit id="eQuestionSubmit">&emsp;提交&emsp;</button>
           </div>
       </div><br><br>
    </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="https://demo.easyweb.vip/iframe/assets/js/common.js?v=318"></script>
<script type="text/javascript" src="https://demo.easyweb.vip/iframe/assets/libs/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
$(top.hangge());
</script>
<script>
    layui.use(['layer', 'admin', 'form', 'table','element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var admin = layui.admin;
        var table = layui.table;
  	  	var form = layui.form;
  	  	var element = layui.element;
  	  	form.on("select(firstMenu)", function(data){
  	  		renderForm(data.value,1)
	    });
  	  	form.on("select(secondMenu)", function(data){
    		renderForm(data.value,2)
  	    });
  	    function renderForm(ctop,ctiter){
	  		let params = {};
	    	params.ctop = ctop;
	    	$.ajax( {
	             url : '/admin/knowledge/nextMenu', 
	             type : 'post',
	             data: params,
	             dataType : 'json',
	             success : function(data) {
	            	let menuList = eval(data);
	            	var menuMessage1 = '<option value="">选择二级目录</option>';
	            	var menuMessage2 = '<option value="">选择目录</option>';
	            	if(ctiter==1){
		            	for(var i in menuList) {
		            		menuMessage1 += '<option value="'+menuList[i].cno+'">'+menuList[i].cname+'</option>';
		            	}
		            	$("#secondMenu").html(menuMessage1);
		            	$("#endMenu").html(menuMessage2)
	            	} else {
	            		for(var i in menuList) {
		            		menuMessage2 += '<option value="'+menuList[i].cid+'">'+menuList[i].cname+'</option>';
		            	}
		            	$("#endMenu").html(menuMessage2);
	            	}
	            	layui.use('form', function(){
	          			var form = layui.form;
	          			form.render();
	          		});
	             }
	         });
  	  	}
        var content = [
            '<div style="text-align: center;color: #fff;background-image: linear-gradient(to right,#009688,#5fb878);padding: 20px;">',
            '   <div style="font-size: 28px;margin-bottom: 10px;">EASY WEB 后台管理模板</div>',
            '   <div style="font-size: 18px">基于Layui的一套通用型后台管理模板，拥有众多原创组件及模板页面</div>',
            '</div><br/>'
        ].join('');
        initT();
        // 渲染富文本编辑器
        function initT(){
	        tinymce.init({
	            selector: '#demoEditor',
	            height: 750,
	            branding: false,
	            language: 'zh_CN',
	            plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
	            toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image media emoticons charmap anchor pagebreak codesample | ltr rtl',
	            toolbar_drawer: 'sliding',
	            images_upload_url: '../../../json/tinymce-upload-ok.json',
	            file_picker_types: 'media',
	            file_picker_callback: function (callback, value, meta) {
	                layer.msg('演示环境不允许上传', {anim: 6});
	            },
	            init_instance_callback: function (editor) {
	                console.log(editor);
	            }
	        });
        }
        $('#eQuestionSubmit').click(function () {
       	 // 获取内容
         var content = tinymce.get('demoEditor').getContent()+'';
       	 if(content===''){
       		layer.msg("请输入内容！", {icon: 5});
    		return false;
       	 }
       	 let endMenu = $("#endMenu").val()+'';
       	 if(endMenu===''){
       		layer.msg("请选择目录！", {icon: 5});
    		return false;
       	 }
         let params = {};
         params.kmessage = content;
         params.ktitle = '标题';
         params.kimg = '';
         params.cno = endMenu;
         $.ajax( {
             url : '/admin/knowledge/addKnowledge', 
             type : 'post',
             data: params,
             dataType : 'json',
             success : function(data) {
            	 if(data.code==0){
            		 layer.msg(data.msg,{icon: 1});
            		 tinymce.get('demoEditor').setContent('', {});
                     tinymce.get('demoEditor').remove();
                     initT();
	        	 }else{
	        		 layer.msg(data.msg,{icon: 2});
	        	 }
             }
         });
       });
        
        
        // 获取内容
        $('#btnDemoEdtGetContent').click(function () {
            var content = tinymce.get('demoEditor').getContent();
            let params = {};
            params.data = content;
            $.ajax( {
	   	        url : '/admin/knowledge/addKnowledge', 
	   	        type : 'post',
	   	        data: params,
	   	        dataType : 'json',
	   	        success : function(data) {
	   	        }
	   	    });
            layer.alert(content, {skin: 'layui-layer-admin', shade: .1});
        });

        // 获取文本
        $('#btnDemoEdtGetText').click(function () {
            var content = tinymce.get('demoEditor').getContent({format: 'text'});
            layer.alert(content, {skin: 'layui-layer-admin', shade: .1});
        });

        // 修改文本
        $('#btnDemoEdtSetContent').click(function () {
            tinymce.get('demoEditor').setContent(content);
        });

        // 插入文本
        $('#btnDemoEdtInsertContent').click(function () {
            tinymce.get('demoEditor').insertContent('👍赞~', {});
        });
        $('#cloneDemoEdtInsertContent').click(function () {
        	tinymce.get('demoEditor').setContent('', {});
            tinymce.get('demoEditor').remove();
            initT();
        });

        // 弹窗中使用
        $('#btnDemoEdtShowLayer').click(function () {
            admin.open({
                title: '富文本编辑器',
                type: 1,
                area: '820px',
                offset: '45px',
                content: '<textarea id="demoEditor2"></textarea>',
                success: function () {
                    tinymce.init({
                        selector: '#demoEditor2',
                        height: 480,
                        branding: false,
                        language: 'zh_CN',
                        plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
                        toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image media emoticons charmap anchor pagebreak codesample | ltr rtl',
                        toolbar_drawer: 'sliding',
                        images_upload_url: '../../../json/tinymce-upload-ok.json',
                        file_picker_types: 'media',
                        file_picker_callback: function (callback, value, meta) {
                            layer.msg('演示环境不允许上传', {anim: 6});
                        },
                        init_instance_callback: function (editor) {
                            tinymce.get('demoEditor2').setContent(content);
                        }
                    });
                },
                end: function () {
                    tinymce.get('demoEditor2').destroy(false);
                }
            });
        });
        // 获取内容
        $('#btnDemoEdtGetContent').click(function () {
            var content = tinymce.get('demoEditor').getContent();
            let params = {};
            params.data = content;
            $.ajax( {
	   	        url : '/admin/knowledge/addKnowledge', 
	   	        type : 'post',
	   	        data: params,
	   	        dataType : 'json',
	   	        success : function(data) {
	   	        }
	   	    });
            layer.alert(content, {skin: 'layui-layer-admin', shade: .1});
        });

    });
</script>
</body>
</html>